<template>
  <div>
    <el-button icon="el-icon-back" circle @click="back"></el-button>
    <el-form ref="form" :model="form" status-icon :rules="rules" label-width="120px">
      <el-form-item label="物证编号">
        <el-input v-model="form.wid" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="物证描述" prop="wtext">
        <el-input v-model="form.wtext"></el-input>
      </el-form-item>
      <el-form-item label="物证提交者编号">
        <el-input v-model="form.uid" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="提交时间">
        <el-input v-model="form.insertdate" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select v-model="form.state" placeholder="请选择状态类型">
          <el-option label="正常" value="正常"></el-option>
          <el-option label="损坏" value="损坏"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="upd">更新</el-button>
        <el-button @click="cancel">恢复</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "EditUser",
  wid:'',
  data(){
    return{
      temp:[],
      form: {
        wid: '',
        wtext: '',
        state: '',
        uid: '',
        insertdate:''
      },
      rules: {
        state: [
          {required: true, message: '物证状态不可为空', trigger: 'blur'}
        ],
        wtext: [
          {required: true, message: '物证描述不可为空', trigger: 'blur'}
        ]
      },
    }
  },
  created: function() {
    this.wid=this.$route.params.wid;
  },
  beforeRouteEnter: (to,from,next) => {
    console.log('进入路由之前');//加载数据
    next(vm => {
      vm.selectinfo();
    })
  },
  methods:{
    back: function (){
      this.$router.push("/func/evidenceList");
    },
    selectinfo: function() {
      this.axios({
        method:"post",
        headers: { 'content-type': 'application/json' },
        url: "http://evidence.frogking.cn/evidenceAdm/selectByWid",
        params:{
          token:localStorage.getItem("token_only"),
          wid:this.wid
        }
      }).then(res=>{
        console.log(res+'!!!')
        if(res["data"]["code"]==='406'){
          this.form=res["data"]["item"];
          this.temp=this.info
        }
        else if(res["data"]["code"]==='410'){
          this.$alert('没有物证', '错误提示', {
            confirmButtonText: '确定'
          });
        }
        else if(res["data"]["code"]==='000'){
          this.$alert('token失效', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.$router.push("/login");
              localStorage.removeItem("token_only");
            }
          });
        }
        else if(res["data"]["code"]==='001'){
          this.$alert('身份不满足，禁止操作', '错误提示', {
            confirmButtonText: '确定'
          });
        }
        else if(res["data"]["code"]==='002'){
          this.$alert('权限不满足，禁止操作', '错误提示', {
            confirmButtonText: '确定'
          });
        }
      }).catch(function (error) {
        console.log(error);
      });
    },
    upd:function(){
      this.axios({
        method:"post",
        headers: { 'content-type': 'application/json' },
        url: "http://evidence.frogking.cn/evidenceAdm/update",
        params:{
          token:localStorage.getItem("token_only"),
          wid: this.wid,
          wtext: this.form.wtext,
          state : this.form.state
        }
      }).then(res=>{
        console.log(res)
        if(res["data"]["code"]==='400'){
          this.$router.push('/func/evidenceList')
        }
        else if(res["data"]["code"]==='401'){
          this.$alert('系统错误！更新异常！', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.$router.push("/func/list");
            }
          });
        }
        else if(res["data"]["code"]==='410'){
          this.$alert('物证不存在！更新异常！', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.$router.push("/func/list");
            }
          });
        }
        else if(res["data"]["code"]==='000'){
          this.$alert('token失效', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.$router.push("/login");
              localStorage.removeItem("token_only");
            }
          });
        }
        else if(res["data"]["code"]==='001'){
          this.$alert('token权限不满足，禁止操作', '错误提示', {
            confirmButtonText: '确定'
          });
        }
        else if(res["data"]["code"]==='002'){
          this.$alert('token权限不满足，禁止操作', '错误提示', {
            confirmButtonText: '确定'
          });
        }
      }).catch(function (error) {
        console.log(error);
      });
    },
    cancel:function (){
        this.selectinfo();
    }
  }

}
</script>
<style scoped>

</style>
